import { View, Image } from '@tarojs/components';
import Taro from '@tarojs/taro';
import React, { Component } from 'react';
import * as T from '../types';
import './landElement.less';
import actions from '../actions/index';
import { connect } from 'react-redux';
import { store2Props } from '../selectors';
import { IPLAND_OSS_HOST } from '../../constant';
import 'taro-ui/dist/style/components/icon.scss';

type IToolsBoxProps = T.IProps & T.IToolsBoxProps;
//@ts-ignore
@connect<Partial<IToolsBoxProps>, T.IToolsBoxState>(store2Props, actions)
export default class Info extends Component<Partial<IToolsBoxProps>, T.IToolsBoxState> {
  constructor(props: IToolsBoxProps) {
    super(props);
  }

  gotoGame(gameType, gamePath) {
    let {
      main: { isAquamarineMember, isCrystalMember },
    } = this.props;

    // 查询活动是否结束
    let result = this.props.actions.action.getGameBaseConfig(gameType);
    result.then((res) => {
      if (res.context) {
        // 非会员可免费玩魔力金币雨1次，会员可玩所有游戏，均可体验所有游戏新人福利一次
        // if (!isAquamarineMember && !isCrystalMember && gameType == 0) {
        // let result = this.props.actions.action.loadUserComputedGameTimes();
        // result.then((data) => {
        // if (data == 0) {
        // 0-新人可以玩金币雨一次
        // Taro.navigateTo({ url: gamePath });
        // } else {
        //   Taro.showToast({
        //     title: '非会员不可玩~',
        //     icon: 'none',
        //   });
        // }
        // });
        Taro.navigateTo({ url: gamePath });
      } else {
        Taro.showToast({
          title: '活动已结束~',
          icon: 'none',
        });
      }
    });
  }

  render() {
    return (
      <View className="LangHomeElement">
        <Image
          className="manghe"
          src={`${IPLAND_OSS_HOST}home/manghe.png`}
          onClick={() => {
            Taro.showToast({
              title: '升级中，敬请期待~',
              icon: 'none',
            });
          }}
        />
        {/* <Image
          className="libao"
          src={`${IPLAND_OSS_HOST}home/libao.png`}
          onClick={() => {
            Taro.navigateTo({ url: '/pages/package-I/treasureBox/index' });
          }}
        /> */}
        <Image
          className="jingbiyu"
          src={`${IPLAND_OSS_HOST}home/jingbiyu.png`}
          onClick={() => {
            this.gotoGame(0, '/pages/package-I/goldCoinsIndex/index');
          }}
        />
        <Image
          className="leyuan"
          src={`${IPLAND_OSS_HOST}home/leyuan.png`}
        />
        <Image
          className="ipshop"
          src={`${IPLAND_OSS_HOST}home/ipshop.png`}
          onClick={() => {
            // Taro.navigateTo({ url: '/pages/package-I/shop/home/index' })
            Taro.showToast({
              title: '升级中，敬请期待~',
              icon: 'none',
            });
          }}
        />
        <Image
          className="molishang"
          src={`${IPLAND_OSS_HOST}home/molishang.png`}
          onClick={() => {
            Taro.showToast({
              title: '升级中，敬请期待~',
              icon: 'none',
            });
          }}
        />
        <Image
          className="wawa"
          src={`${IPLAND_OSS_HOST}home/wawa.png`}
          onClick={() => {
            this.gotoGame(3, '/pages/package-I/catchPlaything/index');
          }}
        />
        <Image
          className="guaguale"
          src={`${IPLAND_OSS_HOST}home/guaguale.png`}
          onClick={() => {
            this.gotoGame(5, '/pages/package-I/scratch/index');
          }}
        />
        <Image
          className="chouka"
          src={`${IPLAND_OSS_HOST}home/chouka.png`}
          onClick={() => {
            this.gotoGame(4, '/pages/package-I/syntheticCardIp/index');
          }}
        />
        <Image
          className="treasureBox"
          src={`${IPLAND_OSS_HOST}home/treasureBox.png`}
          onClick={() => {
            Taro.navigateTo({ url: '/pages/package-I/treasureBox/index' });
          }}
        />
      </View>
    );
  }
}

//create by moon https://github.com/creasy2010/moon
